#ifndef _LS3A5000_
#define _LS3A5000_

#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <errno.h>

#include "programmer.h"
#include "spi.h"
#include <sys/mman.h>

#define MEM_DEV                     "/dev/mem"
#define SPI_CTRL_REG_BASE             0x803200000000
#define SPI_REG_LENGTH                0x8000
#define SPI_MAX_READ_NUM              0x100
#define SPI_CPU_INTERVAL              0x100000000000

#define CSR_CTRL_REG_BASE             0x803000000000
#define CSR_REG_LENGTH                0x9000
#define SPI_SRST_L                    0x1a80

#define ERASE_4         0x20     
#define ERASE_32        0x52 
#define ERASE_64        0xD8
#define ERASE_D7        0xD7
#define ERASE_C4        0xC4
#define ERASE_DB        0xDB
#define ERASE_50        0x50
#define ERASE_81        0x81
#define ERASE_21        0x21
#define ERASE_5C        0x5C
#define ERASE_DC        0xDC

#define CTRLR0     0x0
#define CTRLR1     0x200UL
#define SSIENR     0x400UL
#define MWCR       0xcUL
#define SER        0x800UL
#define BAUDR      0xa00UL
#define TXFTLR     0xc00UL
#define RXFTLR     0xe00UL
#define TXFLR      0x1000UL
#define RXFLR      0x1200UL
#define SR         0x1400UL
#define IMR        0x1600UL
#define ISR        0x1800UL
#define RISR       0x1a00UL
#define TXOICR     0x1c00UL
#define RXOICR     0x1e00UL
#define RXUICR     0x2000UL
#define MSTICR     0x2200UL
#define ICR        0x2400UL
#define DMACR      0x2600UL
#define DMATDLR    0x2800UL
#define DMARDLR    0x54UL
#define IDR        0x2c00UL
#define SSI_COMP_VERSION  0x2e00UL
#define DR                0x3000UL
#define RX_SAMPLE_DLY     0x7800UL
#define RSVD0             0x7a00UL
#define RSVD1             0x7c00UL
#define RSVD2             0x7e00UL

#define CONST     const
#define STATIC    static
#define VOID      void

#define MmioWrite32(addr, val)         *((volatile uint32_t *)(addr)) = (val)
#define MmioWrite8(addr, val)          *((volatile uint8_t *)(addr)) = (val)

#define MmioRead32(addr)         *((volatile uint32_t *)(addr))

typedef off_t     SPI_PHYS_ADDR;
typedef uint8_t   *SPI_VIRT_ADDR;
typedef size_t    MAP_SIZE;
typedef unsigned long long  UINT64;
typedef long long           INT64;
typedef unsigned int        UINT32;
typedef int                 INT32;
typedef unsigned short      UINT16;
typedef unsigned short      CHAR16;
typedef short               INT16;
typedef unsigned char       BOOLEAN;
typedef unsigned char       UINT8;
typedef char                CHAR8;
typedef signed char         INT8;
typedef UINT64              UINTN;
typedef INT64               INTN;

typedef struct _SW64_FLASH_MEMMAP {
  SPI_VIRT_ADDR          spi_ctrl_reg_base_virt;
  SPI_VIRT_ADDR          csr_ctrl_reg_base_virt;
} SW64_FLASH_MEMMAP;

#endif